<script type="text/javascript">
	function StudentInfoCtrl(CtrlUtil, $http, $element, $injector, $q, modalService, $scope) {
		var ctrl = this;
		ctrl.pageNumber = 0;
		ctrl.qs = -1;
		this.query = function() {
			this.currentCtrl.query()
		};
		this.studentCtrl = {
			query : function() {
				ctrl.entities && (ctrl.entities.content = {})
				var p = CtrlUtil.getQueryParams(ctrl)
				$http.post(':root/trainee/queryStudents', p).success(function(r) {
					ctrl.entities = r;
				})
			}
		}
		this.secretaryCtrl = {
			query : function() {
				ctrl.entities && (ctrl.entities.content = {})
				var p = CtrlUtil.getQueryParams(ctrl)
				p.sftzs = 1
				$http.post(':root/trainee/queryStudents', p).success(function(r) {
					ctrl.entities = r;
				})
			}
		}
		this.currentCtrl = this.studentCtrl
		this.reset = function() {
			CtrlUtil.resetQueryParams(ctrl)
		}
		$http.post(':root/term/queryTerms').success(function(r) {
			ctrl.terms = r.content
			ctrl.termQueryParam = ctrl.terms.length > 0 ? ctrl.terms[0].id : ''
			ctrl.getClassInfo(ctrl.termQueryParam)
			ctrl.query()
		})
		CtrlUtil.loadDepartment(ctrl)
		this.searchStudent = function(name, target) {
			$http.post(':root/trainee/queryRawStudent', {
				name : name
			}).success(function(r) {
				target = target || ctrl
				target.students = r
			})
		}

		this.getClassInfo = function(term, target) {
			target = target || ctrl
			return $http.post(':root/trainee/getClassInfoList', {
				term : term
			}).success(function(r) {
				target.classInfoList = r
			})
		}
		this.singleRecord = function() {
			var content = $element.find('[template]>form[single-student]').clone()
			var param = {
				title : '学员录入',
				content : content,
				search : {
					enable : true
				},
				student : {},
				result : {
					jrfs : 1,
					term : {
						id : ctrl.termQueryParam
					},
					sfwtzs : 0,
					sfsqtzs : 0,
					xq : '仙林校区',
					status : 0
				},
				ctrl : ctrl
			}
			return ctrl.getClassInfo(ctrl.termQueryParam, param).success(function() {
				return modalService.confirm(param, {
					backdrop : false
				}).then(function(r) {
					$http.post(':root/trainee/add', r).success(function(r) {
						modalService.succ('添加成功', 1500)
						ctrl.query();
					})
				})
			})
		}
		this.edit = function(item) {
			var content = $element.find('[template]>form[single-student]').clone()
			var param = {
				title : '学员编辑',
				content : content,
				search : {
					enable : false,
					student : item.student
				},
				result : item,
				ctrl : ctrl
			}
			return ctrl.getClassInfo(item.term.id, param).success(function() {
				return modalService.confirm(param, {
					backdrop : false
				}).then(function(r) {
					$http.post(':root/trainee/add', r).success(function(r) {
						modalService.succ('修改成功', 1500)
						ctrl.query();
					})
				})
			})
		}
		this.checkAll = function(b) {
			CtrlUtil.checkAll(ctrl, b)
		}
		this.import = function() {
			var content = $element.find('[import]').clone()
			var modal = modalService.show({
				title : '学员批量录入',
				content : content,
				upload : function() {
					content.find('form').ajaxForm().ajaxSubmit({
						url : require.toUrl('root/trainee/importStu'),
						success : function(r) {
							if (r == '') {
								modalService.succ('导入成功', 1500)
							} else {
								modalService.succ('导入失败：' + r, 1500)
							}
							modal.close()
						},
						error : function() {
							modalService.error('导入失败', 1500)
						}
					});
				},
				term : ctrl.termQueryParam,
				supCtrl : ctrl
			}, {
				backdrop : false
			})
		}
	}
</script>
<!-- Search area -->
<div ng-controller="StudentInfoCtrl as ctrl" >
	<div class="panel panel-cys">
		<div class="panel-heading">
			<h3 class="panel-title">
				<span class="glyphicon glyphicon-search"></span>
				信息查询
			</h3>
		</div>
		<div class="panel-body">
			<div class="container-fluid">
				<form class="form-horizontal row">
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<select class="form-control" ng-change="ctrl.getClassInfo(ctrl.termQueryParam)" chosen
								ng-options="m.id as (m.name+'-第'+m.qs+'期') for m in ctrl.terms" ng-model="ctrl.termQueryParam">
								<option value="">期次</option>
							</select>
						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<input placeholder="学号/姓名" ng-model="ctrl.nameQueryParam" type="text" class="form-control">
						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<input placeholder="年级" ng-model="ctrl.gradeQueryParam" type="text" class="form-control">
						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<select class="form-control" chosen ng-change="ctrl.changeDepartment()" ng-options="m.id as m.name for m in ctrl.departments"
								ng-model="ctrl.departmentQueryParam">
								<option value="">院系</option>
							</select>

						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<select class="form-control" chosen ng-options="m.id as m.bjName for m in ctrl.classInfoList" ng-model="ctrl.clazzQueryParam">
								<option value="">班级</option>
							</select>
						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<select chosen ng-model="ctrl.xqQueryParam" class="form-control">
								<option value="">校区</option>
								<option>仙林校区</option>
								<option>鼓楼校区</option>
							</select>
						</div>
					</div>
					<div class="form-group col-md-4 remove-margin-horizontal">
						<div class="col-md-10 col-md-offset-1">
							<select chosen ng-model="ctrl.statusQueryParam" class="form-control">
								<option value="">状态</option>
								<option value="0">正常学习</option>
								<option value="1">保留成绩</option>
								<option value="2">退出学习</option>
							</select>
						</div>
					</div>
					<div class="form-group col-md-12 remove-margin-horizontal ">
						<div class="col-md-8  pull-right">
							<div class="pull-right ">
								<button ng-click="ctrl.query()" type="submit" class="btn btn-cys btn-sm">
									<span class="glyphicon glyphicon-search"></span>
									查询
								</button>
								<button ng-click="ctrl.reset()" type="reset" class="btn btn-default btn-sm">
									<span class="glyphicon glyphicon-repeat"></span>
									重置
								</button>
							</div>
						</div>
					</div>
				</form>
			</div>
		</div>
	</div>
	<!-- Search area END -->
	<!-- <ul class="nav nav-tabs" role="tablist" style="margin-bottom: 10px;">
		<li ng-click="ctrl.currentCtrl=ctrl.studentCtrl;ctrl.query()" role="presentation" ng-class="{active:ctrl.currentCtrl==ctrl.studentCtrl}">
			<a href="javascript:;" aria-controls="home" role="tab" data-toggle="tab">
				<span class="glyphicon glyphicon-user"></span>
				学员管理
			</a>
		</li>
		<li ng-click="ctrl.currentCtrl=ctrl.secretaryCtrl;ctrl.query()" role="presentation"
			ng-class="{active:ctrl.currentCtrl==ctrl.secretaryCtrl}">
			<a href="javascript:;" aria-controls="profile" role="tab" data-toggle="tab">
				<span class="glyphicon glyphicon-star"></span>
				团支书管理
			</a>
		</li>
	</ul> -->
	<!-- operation area -->
	<!-- data grid area END -->

	<div class="tab-content">
		<!-- 学员管理 -->
		<div class="tab-pane active">
			<!-- operation area -->
			<div class="" ng-show="ctrl.currentCtrl==ctrl.studentCtrl">
				<button type="button" class="btn btn-cys btn-sm" data-toggle="modal" ng-click="ctrl.singleRecord()">
					<span class="glyphicon glyphicon-import"></span>
					学员单个录入
				</button>
				<button type="button" class="btn btn-cys btn-sm" ng-click="ctrl.import()">
					<span class="glyphicon glyphicon-indent-left"></span>
					学员批量录入
				</button>
				<a type="button" ng-click="mainCtrl.toDispatch()" class="btn btn-cys btn-sm">
					<span class="glyphicon glyphicon-fullscreen"></span>
					分班管理
				</a>
				<a type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/trainee/exportStu')">
					<span class="glyphicon glyphicon-export"></span>
					导出
				</a>
				<div class="pull-right" ng-include="':root/components/page.html'"></div>
			</div>
			<div class="" ng-show="ctrl.currentCtrl==ctrl.secretaryCtrl">
				<a type="button" class="btn btn-cys btn-sm" ng-click="export(ctrl,'root/trainee/exportStu',{sftzs:1})">
					<span class="glyphicon glyphicon-export"></span>
					导出
				</a>
				<div class="pull-right" ng-include="':root/components/page.html'"></div>
			</div>

			<!-- operation area END -->
			<!-- data grid area -->
			<div style="padding-top: 10px;">
				<table class="table table-bordered table-hover table-striped">
					<tr>
						<th>
							<input ng-change="ctrl.checkAll(ctrl.$checkAll)" ng-model="ctrl.$checkAll" type="checkbox" />
						</th>
						<th>姓名</th>
						<th>性别</th>
						<th>学号</th>
						<th>年级</th>
						<th>院系</th>
						<!-- <th>专业</th> -->
						<th>所属班级</th>
						<th>学习状态</th>
						<th>联系电话</th>
						<th>校区</th>
						<th>团支书</th>
						<th>操作</th>
					</tr>
					<tr ng-repeat="item in ctrl.entities.content">
						<td>
							<input ng-model="item.$checked" type="checkbox" />
						</td>
						<td>{{item.user.name}}</td>
						<td>{{item.sexString}}</td>
						<td>{{item.user.uid}}</td>
						<td>{{item.user.grade}}</td>
						<td>{{ctrl.departmentMap[item.user.department].name}}</td>
						<!-- <td>{{item.student.major.name}}</td> -->
						<td>{{item.classInfo.bjName}}</td>
						<td>
							<span ng-switch="item.status">
								<span ng-switch-when="0">正常学习</span>
								<span ng-switch-when="1">保留成绩<</span>
								<span ng-switch-when="2">退出学习</span>
							</span>
						</td>
						<td>{{item.phone}}</td>
						<td>{{item.xq}}</td>
						<td>{{item.sfwtzs|toBool}}</td>
						<td>
							<a href="javascript:;" class="remove-underline" ng-click="ctrl.edit(item)">编辑</a>
						</td>
					</tr>
				</table>
				<p>
					共有记录：
					<span>{{ctrl.entities.totalElements}}</span>
					条
				</p>
			</div>
			<!-- data grid area END -->
			<!-- pagination bar -->
			<!-- pagination bar END -->
		</div>
		<!-- 团支书管理 -->
	</div>
	<div template ng-non-bindable class="hidden">
		<div import class="col-md-10 col-md-offset-1">
			<form class="form-horizontal" enctype="multipart/form-data" method="post">
				<div class="form-group">
					<div class="col-md-12 ">
						<select name="term" class="form-control" chosen ng-value="term">
							<option value="">期次</option>
							<option value="{{m.id}}" ng-selected="$index==0" ng-repeat="m in supCtrl.terms">{{(m.name+'-第'+m.qs+'期')}}</option>
						</select>
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<input class="form-control" id="fileImport" name="file" type="file" />
					</div>
				</div>
				<div class="form-group">
					<div class="col-md-12">
						<a type="submit" ng-click="upload()" class="btn btn-success">导入</a>
						<a class="btn btn-link btn-sm" href="asset/excel/studenImportSample.xls">
							<span class="glyphicon glyphicon-arrow-down"></span>
							导入模板下载
						</a>
					</div>
				</div>
			</form>
		</div>
		<form class="form-horizontal" single-student>
			<div class="form-group" ng-show="search.enable">
				<label class="col-md-2 control-label">学生</label>
				<div class="col-md-10 open">
					<input type="text" ng-change="ctrl.searchStudent(search.name,search)" ng-model="search.name" class="form-control"
						placeholder="按姓名/学号模糊搜索">
					<ul class="dropdown-menu" ng-show="search.students.content.length>0">
						<li ng-repeat="t in search.students.content">
							<a href="javascript:;" ng-click="search.student=t;result.student.id=t.id;search.students=null;">({{t.xh}}){{t.name}}</a>
						</li>
					</ul>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">姓名</label>
				<div class="col-md-4">
					<input type="text" ng-model="search.student.name" class="form-control" disabled="disabled">

				</div>
				<label class="col-md-2 control-label">性别</label>
				<div class="col-md-4">
					<input type="text" class="form-control" ng-model="search.student.sexString" disabled="disabled">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">学生类别</label>
				<div class="col-md-4">
					<input type="text" class="form-control" disabled="disabled" value="本科">
				</div>
				<label class="col-md-2 control-label">年级</label>
				<div class="col-md-4">
					<input type="text" class="form-control" ng-model="search.student.grade" disabled="disabled" value="2015">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">院系</label>
				<div class="col-md-4">
					<input type="text" class="form-control" disabled="disabled" ng-model="search.student.department.name">
				</div>
				<label class="col-md-2 control-label">专业</label>
				<div class="col-md-4">
					<input type="text" class="form-control" disabled="disabled" ng-model="search.student.major.name">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">校区</label>
				<div class="col-md-4">
					<select class="form-control" ng-model="result.xq">
						<option>仙林校区</option>
						<option>鼓楼校区</option>
					</select>
				</div>
				<label class="col-md-2 control-label">联系电话</label>
				<div class="col-md-4">
					<input type="text" ng-model="result.lxfs" class="form-control">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">班级</label>
				<div class="col-md-4">
					<select class="form-control" ng-options="m.id as m.bjName for m in classInfoList " ng-model="result.classInfo.id">
					</select>
				</div>
				<label class="col-md-2 control-label">团支书</label>
				<div class="col-md-4">
					<select class="form-control" ng-model="result.sfwtzs">
						<option value="1">是</option>
						<option value="0">否</option>
					</select>
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">备注</label>
				<div class="col-md-10">
					<input type="text" class="form-control" ng-model="result.bz">
				</div>
			</div>
			<div class="form-group">
				<label class="col-md-2 control-label">状态</label>
				<div class="col-md-4">
					<select class="form-control" ng-model="result.status">
						<option value="0">正常学习</option>
						<option value="1">保留成绩</option>
						<option value="2">退出学习</option>
					</select>
				</div>
				<label class="col-md-2 control-label">所属期次</label>
				<div class="col-md-4">
					<select class="form-control" ng-options="m.id as (m.name+'-第'+m.qs+'期') for m in ctrl.terms" ng-model="result.term.id">
					</select>
				</div>
			</div>
		</form>
	</div>
</div>